package cn.imvc.app.controllers.goods;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;

import cn.imvc.app.entities.GoodsClass;
import cn.imvc.app.models.GoodsClassModel;
import cn.imvc.app.models.LoggingModel;
import cn.imvc.core.DialogBean;
import cn.imvc.core.Render;
import cn.imvc.data.domain.ViewRequest;
/**
 * 
 * @author zhy
 * @date 2016年7月16日下午5:15:38
 *
 */
public class GoodsClassControllerImpl implements GoodsClassController{
	static Logger logger = Logger.getLogger(GoodsClassControllerImpl.class);
	public Page<GoodsClass> page;
	public ViewRequest viewRequest;
	public GoodsClass goodsClass;
	public String goodsClassTree;
	public int id;
	public int classId;
	private int goods_id;
	public int[] ids;
	public String gcTree;
	private String search_content;
	
	/**
	 * 多选的查找带回
	 * @return
	 */
	private String multipleDialogMyIds;
	private String multipleDialogMyNames;
	@Autowired
	LoggingModel loggingModel;
	@Autowired
	private GoodsClassModel goodsClassModel;
	
	public String search() {
		
		return null;
	}

	public String index() {
		goodsClassTree = goodsClassModel.getGoodsClassTree();
		return "goods-class/index";
	}

	public String show() {
		
		return "goods-class/show";
	}

	public String showAll(){
		gcTree=goodsClassModel.treeLookup();
		return "goods-class/dialog";
	}
	
	public String editNew() {
		goodsClass  = goodsClassModel.get(id);
		return "goods-class/editNew";
	}

	public String create() {
		goodsClassModel.save(id,goodsClass);
		return Render.json(new DialogBean("200","创建成功","goods-class","closeCurrent"));
	}

	public String edit() {
		if(id == 0){
			return Render.json(new DialogBean("300", "没有所需要的内容！","goods-class", "closeCurrent"));
		}
		goodsClass = goodsClassModel.get(id);
		return "goods-class/edit";
	}

	public String update() {
		goodsClassModel.update(id,goodsClass);
		return Render.json(new DialogBean("200","修改成功","goods-class"));
	}

	public String destroy() {
		if(id == 0){
			return Render.json(new DialogBean("300", "没有所删除的内容！","goods-class", "closeCurrent"));
		}
		String result = goodsClassModel.delete(id);
		if(result.equals("")){
			return Render.json(new DialogBean("200","删除成功","goods-class"));
		}else{
			return Render.json(new DialogBean("300", result,"goods-class")); 
		}
		
	}

	public String destroyBatch() {
		
		return null;
	}
	

    public String detail(){
    	goodsClass = goodsClassModel.get(id);
    	return "goods-class/show";
    	
    }
    
    /**
     * 多选的dialog
     */
    public String multipleDialog(){
    	if(viewRequest==null){
			viewRequest = new ViewRequest();
		}
		viewRequest.getSort().put("sort", "ASC");
		if(search_content != null && !search_content.trim().equals("")){
			viewRequest.getParams().put("name_like", search_content);
			viewRequest.getParams().put("_or_sort_like", search_content);
		}
    	page = goodsClassModel.find(viewRequest);
    	return "goods-class/multipleDialog";
    }

	public String getMultipleDialogMyIds() {
		return multipleDialogMyIds;
	}

	public void setMultipleDialogMyIds(String multipleDialogMyIds) {
		this.multipleDialogMyIds = multipleDialogMyIds;
	}

	public String getMultipleDialogMyNames() {
		return multipleDialogMyNames;
	}

	public void setMultipleDialogMyNames(String multipleDialogMyNames) {
		this.multipleDialogMyNames = multipleDialogMyNames;
	}

	public String getSearch_content() {
		return search_content;
	}

	public void setSearch_content(String search_content) {
		this.search_content = search_content;
	}

	public ViewRequest getViewRequest() {
		return viewRequest;
	}

	public void setViewRequest(ViewRequest viewRequest) {
		this.viewRequest = viewRequest;
	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public int getClassId() {
		return classId;
	}

	public void setClassId(int classId) {
		this.classId = classId;
	}

	public int[] getIds() {
		return ids;
	}

	public void setIds(int[] ids) {
		this.ids = ids;
	}
    
	public GoodsClass getGoodsClass() {
		return goodsClass;
	}

	public void setGoodsClass(GoodsClass goodsClass) {
		this.goodsClass = goodsClass;
	}

	public String getGoodsClassTree() {
		return goodsClassTree;
	}

	public void setGoodsClassTree(String goodsClassTree) {
		this.goodsClassTree = goodsClassTree;
	}

	public int getGoods_id() {
		return goods_id;
	}

	public void setGoods_id(int goods_id) {
		this.goods_id = goods_id;
	}

	public String getGcTree() {
		return gcTree;
	}

	public void setGcTree(String gcTree) {
		this.gcTree = gcTree;
	}
}
